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
*#
%-&$* /1*& &&*&*

###
-*
 1&&
A&;'
%%&%
# "
! 0
,*#
",*
"(
 1'&&
%%;
'&%&%
&F$3
,AJ
%-A 
$-3
 0#
#;+K-
00
 1'&&
%;'
&%'&
%%%G
&%
!  
"*
04$./12A
;)./-*%*%-)*A
" ?A
* 
0 
"0 
)./-* /
(
"1'&&
''
;'G%'G
%'''

B;"
#"A;
% ,
;;
"*0* 
0,
;;
;(
$ 1'&&
D@&%
&%"$;
'%'
@&%
! "7+
B5>%-4 
B5&$&"7
"!5>%-4 )&
#7+;/"*

A""
"B"
 ,
A)./-*A 
)./-*
")./-*A(
( H
""
' *"
 "
 ;","
*"C
*"

<=
<L
<@
*0+KGH
G,H "MN

7K
B0
O
(
*0'"
G)H
79 What is the correct outcome of the SQL query below?
*"0#,&-$.&*/&-*
"
  ;9+879+
MNMN"
"6
" %&&';&&D&&;
G%
" &&&&
%'<A"=&
&&'I*+BB>B
?1?1BJ
B: 7);
 ":)
+ := :+=
@ +
"" &6K#%9
SELECT Count(*) FROM ( (SELECT Borrower, Bank_Manager FROM
Loan_Records) AS S NATURAL JOIN (SELECT Bank_Manager, Loan_Amount FROM
Loan_Records) AS T );
&&';
"$ &&&;
Query: SELECT Company, AVG(Salary) FROM AV1 HAVING AVG(Salary) > 1200 GROUP
BY Company WHERE Salary > 1000 ;
This query will give the error because ‘WHERE’ is always evaluated before ‘GROUP BY’
and ‘Having’ is always evaluated after ‘GROUP BY’.
"(D%'&
B&
*#
& P0
"500(
",D!4&%
2#'
%?
'

*0%"
;
  ,
I&I
;I% ;I&!*$%45*./*&$P.%-I

%0 "$%45*./*&$P.%-

P.%- "
IAI&I
".&%
8I4I

"/ %
&* 3L3L/(3
LL/,$
$3 D&
&;&'3333
$ D&%
;&
&M
$ 0D&&&&
'
2""
A 

2;8,"%
P ,#


;
.80
D"*" 
, ,, 

$ *I*I'&0%
)A%"A%;
/A%I/I&-/
MN MAA"N MAAN
B0#0
.9 :K9<.< 
:K9<!" 0


>&&G&GM
select
result.Request_at as "Day",
round(sum(case when result.Status = 'completed' then 0 else 1
end) / count(*), 2) as "Cancellation Rate"
from (
select
Driver_Id,
Status,
Request_at
from trips left join users on trips.client_id=users.users_id
where users.banned = 'NO'
) result
left join users on result.driver_id=users.users_id
where
users.Banned ='NO'
and result.Request_at between '2013-10-01' and '2013-10-03'
group by
result.Request_at
$" ;D&&&%&
&7
24&A;&&&'
&M
&M

"Q9
$$NOO&A;D&&
P'%
<P=
*,
R*&%!!I;
"
$(>OB&O&&&&&%&'
'B&A
&%&'
4"I&I 0#
!"
 P

>&5'&&
&M
$,>OB&O&&&&&B
&A&A&%&

$. X city opened a new cinema, many people would like to go to
this cinema. The cinema also gives out a poster indicating the
movies’ ratings and descriptions.
Please write a SQL query to output movies with an odd numbered
ID and a description that is not 'boring'. Order the result by rating.
For example, table cinema:
$/
!' ""& In

I
InIJ:I:KK%In

I 
0I
(3 
%-
""
 "94/%
C"
%S4/%'
( 4
'"
"

'
;*R" 
;R" 
! '*'
'; 
R0"
(?78
);"
0"B 
;'
#;*;
!3
(D
&'
/#'"
"" 
*;'  
!A-%
"L%
#!AA
"L
("B4&&&&
"
*"
"$)5
"($/ 
$) $$ 6
";'"
&**$-)*%.-%.*%.-&>& 
6"
"
($ B4&1%L1%1%L7%&
%D'
5"'"
D ;
#"S"
"S1"";

"
(( &%G%&
;""
;;; ;";;
;&";;
 ;*
" "
#8;8;;
#"T+ "
=KD"
(, &%&&A?&
+@%&4
/'51;;
.5
"'  ;
*%;
/'
'
;'

(. %&)%&
>G
;
/"
;  
"/
;,",
&; /*P"
"U'%, 
#"
;'
(/0'QQB##*#QQ#*?*:+>

%VV$;&;
"K"VV$"
VV$;8
;VV&*
VVVV
"&&)*V$)J
VV$.B)./-* V&$JVV&$$.$
,3 ?0B?8?
)5&)3"
*;

, 2&&'&A%A
A;&%
%%&&%
, 2&&'&%
A;%'
%A%'%'
,
=7
=+
,( BB?>
,, 1&
 
 $%

0% 
0
#I%&
O
'I1I;

-" ;

,. &-
6"6 
6"
*"
;*
6"
0"86
,/ %#*7>#:+?1>B

% 
*8#
 ; 
"*
  
;  "
#5"  "
'
.3 %BB>B
>#:+?1>B
**$/-)*&

*&&*&
"
#

. '
%#
%#


. 0%%D$%%'
*!
'(
/*$%-4- 9 +

. 7%
1
"

'""0"
"
." ?&&
)#
)
#0
8" 

.$ 

*
 "
B"

.( G
;0%
"-/" 0"
";
#
., :;8
*;"
"/03*
0;;
0
.. %7G
:;8
1/0;0"
;""/0;
 1;
0;
./ 'G
;
; 
;
/3 B#&
BMI&   #,

#&MI$

/ 1?
*)% ) % 
 * ;      )%

 

*
 

)
"*""
#
),"


 
  # 
;
/ G<=%
*R
#
/ %N4&
"
%         
        
B"
    '  " 
"0
        
       
        0 * 
''
0
/"2&&'%&A;
%<
%='5'
%A%%5
<3=
@+ From the given trips and users tables for a taxi service, write
a query to return the cancellation rate in the first two days in
October, rounded to two decimal places, for trips not involving
banned riders or drivers. From LeetCode.
/( B4&%*>7*17
*>7MO%.*1 

W8.
.*1
;*.*1
6;
*
8 0
"" 
  
 R"

*17(.1.1 
#
"0!.1
 W
5 
 
8
/,&)
P,5 
 
,
/. %::1&&

*I:I
!' #
#% 
#%* /
%/
  
#
//   ? 0   ?
 )       "
N%
        )  '
   "  ; '
 
" &)$&
&&)*

*6 .1&-

*' 
!&*)5
*" ).&'
! &.)*&


33%
*%

 **"
%

